package com.atguigu.cloud.user.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.atguigu.cloud.user.block.SentinelBlockHandler;
import com.atguigu.cloud.user.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/param")
public class TestParamController {

    //1、请求参数
    //1.1 简单类型 @RequestParam
    @GetMapping("/test1")
    @SentinelResource(value = "test1Resource",blockHandlerClass = SentinelBlockHandler.class,blockHandler = "test1")
    public String test1(String username , String password){
        System.out.println(username+" , "+password);
        return "success-test1";
    }
    //1.2 POJO入参：  实体类
    @GetMapping("/test2")
    @SentinelResource(value = "test2Resource",blockHandlerClass = SentinelBlockHandler.class,blockHandler = "test2")
    public String test2(User user){
        System.out.println(user);
        return "success-test2";
    }
    //1.3 Map/List入参：
    @GetMapping("/test3")
    @SentinelResource(value = "test3Resource",blockHandlerClass = SentinelBlockHandler.class,blockHandler = "test3")
    public String test3(@RequestParam Map user){
        System.out.println(user);
        return "success-test3";
    }
    @GetMapping("/test4")
    @SentinelResource(value = "test4Resource",blockHandlerClass = SentinelBlockHandler.class,blockHandler = "test4")
    public String test4(@RequestParam List<Long> ids){
        System.out.println(ids);
        return "success-test4";
    }
    //2、请求体
    @PostMapping("/test5")
    @SentinelResource(value = "test5Resource",blockHandlerClass = SentinelBlockHandler.class,blockHandler = "test5")
    public String test5(@RequestBody User user){
        System.out.println(user);
        return "success-test5";
    }
    //400 controller接口必须要求的参数 请求没有提交
    @GetMapping("/test6")
    @SentinelResource(value = "test6Resource",blockHandlerClass = SentinelBlockHandler.class,blockHandler = "test6")
    public String test5(@RequestHeader("token") String token){
        System.out.println(token);
        return "success-test6";
    }

}